from fastapi import APIRouter, Depends
from sqlalchemy.orm import Session
from starlette.requests import Request

from annotation.log_annotation import log_decorator
from common.get_db import get_db
from module_sys.service.UserService import UserService
from utils.http_base import unified_resp

router = APIRouter()


@router.get('/index')
@unified_resp
@log_decorator(title='角色管理', business_type=1)
async def index():
    return 'success'

@router.get('/index2')
@unified_resp
async def index():
    return 'error'

@router.get('/redis')
@unified_resp
async def index(request: Request):
    dict_data_query_result = await request.app.state.redis.get('test')
    return dict_data_query_result


@router.get('/db')
@unified_resp
async def db(request: Request, query_db: Session = Depends(get_db)):
    return UserService.get_user_list_services(query_db)


@router.get('/db2')
@unified_resp
async def db(request: Request):
    return UserService.getUserInfo()
